import UIKit
//定义一个基类
class Vehicle {
    var currentSpeed = 0.0
    var description : String {
        return "travleing at \(currentSpeed) miles per hour"
    }
    
    func makeNoise() {
        
    }
}
let someVehicle = Vehicle()
//子类
class Bycyle: Vehicle {
    var hasBasket = false
}
let bicycle = Bycyle()
bicycle.description
class Tandem : Bycyle {
    var currentNumberOfPassager = 0
}

let tandom = Tandem()
tandom.hasBasket = true
tandom.currentNumberOfPassager = 2
tandom.currentSpeed = 22.0

//重写 Override 子类可以为继承来的实例方法，类方法，，实例属性，下标提供自己的实现。
//访问 超类的方法，属性和下标 super
//重写
class Train: Vehicle {
    override func makeNoise() {
         print("Choo Choo")
    }
}

let trin = Train()
trin.makeNoise()
//您可以提供定制的getter或setter来重写任意继承来的属性。
class Car: Vehicle{
    var gear = 1
    override var description: String {
        return super.description + " in gear \(gear)"
    }
}

let car = Car()
car.currentSpeed = 25.0
car.gear = 1
car.description

//重写属性观察器 didset
class AutomaticCar: Car {
    override var currentSpeed: Double {
        didSet {
            gear = Int(currentSpeed / 10.0) + 1
        }
    }
}

let auto = AutomaticCar()
auto.currentSpeed = 35.0
print("automatic car: \(auto.description)")

//防止重写 final(final var,final func, final clas func, final subscript, final class)
